package org.jeecg.modules.demo.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.demo.crm.entity.CAdditionalRequest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 增项需求表
 * @Author: jeecg-boot
 * @Date:   2025-06-18
 * @Version: V1.0
 */
public interface CAdditionalRequestMapper extends BaseMapper<CAdditionalRequest> {

    @Select("select * from c_additional_request where sub_project_id =#{subProjectId}  limit 1")
    CAdditionalRequest findBySubProjectId(@Param("subProjectId") String subProjectId);

    @Select("select * from c_additional_request where status =#{status} ")
    List<CAdditionalRequest> findByStatus(@Param("status")String status);

    @Select("select * from c_additional_request where status =#{status}  AND ( create_time >= DATE_SUB(NOW(), INTERVAL 1 DAY)OR update_time >= DATE_SUB(NOW(), INTERVAL 1 DAY))")
    List<CAdditionalRequest> gather(@Param("status")String status);

    @Select("select count(*) from c_additional_request where project_number = #{projectNumber}")
    Integer findByProjectNumber(@Param("projectNumber")String projectNumber);

    @Select("select count(*) from c_additional_request where project_number = #{projectNumber} and id <>#{id}")
    int findByProjectNumberAndId(@Param("projectNumber")String projectNumber, @Param("id")String id);

    @Update("update c_additional_request set sub_project_id =null,status='待报价' where sub_project_id=#{subProjectId}")
    void unbindingSubProjectId(@Param("subProjectId") String subProjectId);
}
